package com.yiwei.zhh.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yiwei.zhh.R;
import com.yiwei.zhh.adapter.base.ItemAdapter;
import com.yiwei.zhh.model.DealTypesV3Model;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class SelectDateV3Adapter extends ItemAdapter<String, SelectDateV3Adapter.DefaultHolder> {


    public SelectDateV3Adapter(Context context) {
        super(context);
    }

    public boolean isCanEdit = true;
    private int selectPoi = 0;

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_select_money, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        String item = getItem(position);
        holder.txtContent.setText(item);
        if (selectPoi == position) {
            holder.txtContent.setBackgroundResource(R.drawable.bg_radius_x10_blue);
            holder.txtContent.setTextColor(0xffFFFFFF);
        } else {
            holder.txtContent.setBackgroundResource(R.drawable.bg_radius_x10_stroke_blue);
            holder.txtContent.setTextColor(0xff4C81FF);
        }
//        holder.txtContent.setBackgroundResource(R.drawable.bg_radius_x10_stroke_grey);
        holder.txtContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isCanEdit) {
                    selectPoi = position;
                    if (onChooseListener != null) {
                        onChooseListener.onClick(item);
                    }
                    notifyDataSetChanged();
                }
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_content)
        TextView txtContent;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public void setCanEdit(boolean isCanEdit) {
        this.isCanEdit = isCanEdit;
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(String name);
    }
}
